﻿using Colorful.Database;
using Colorful.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Colorful.CMS.Core
{
    #region MyActionFilter
    public class MyActionFilter : IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext context)
        {
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {

        }
    }
    #endregion

    #region MyExceptionFilter
    public class MyExceptionFilter : IExceptionFilter
    {
        public void OnException(ExceptionContext context)
        {
            if (context.Exception != null)
            {
                if (context.Exception is InvalidLoginException)
                    context.Result = new RedirectResult("/logout");
                else
                    WebService.WriteErrorLog(context.Exception);
            }
        }
    }
    #endregion
}
